/*  
  -- The Lime II Project -- 

  A tuplespaces-based middleware for coordinating agents and mobile hosts.
  Copyright (C) 2005.
  Gian Pietro Picco, Amy L. Murphy, Lorenzo Bellini.

  This library is free software; you can redistribute it and/or
  modify it under the terms of the GNU Lesser General Public
  License as published by the Free Software Foundation; either
  version 2.1 of the License, or (at your option) any later version.

  This library is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  Lesser General Public License for more details.

  You should have received this copy of the GNU Lesser General Public
  License along with this library; if not, write to the Free Software
  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 
*/

package lime2;

/**
 * Provides textual representation for LimeConstants and Policies. 
 * 
 * @author Gian Pietro Picco
 * @author Amy Murphy
 * @author Lorenzo Bellini
 */ 

public class Translator implements LimeConstants, Policies, Failures 
{
 /**
  * Translates the codes for <code>Op.type</code> into Strings.
  * 
  * @param type of <code>Op.type</code>
  * @return textual representation
  */	
 public static String translateType(byte type)
 {
  String ret = "?";	
  switch (type)
  {
   case RD                : ret = "RD";                break;
   case RDG               : ret = "RDG";               break;
   case RDP               : ret = "RDP";               break;  
   case IN                : ret = "IN";                break;
   case ING               : ret = "ING";               break;
   case INP               : ret = "INP";               break; 
   case OUT               : ret = "OUT";               break;
   case OUTG              : ret = "OUTG";              break;
   case INSTALL_STRONG    : ret = "INSTALL STRONG";    break;
   case REMOVE_STRONG     : ret = "REMOVE STRONG";     break;
   case INSTALL_WEAK      : ret = "INSTALL WEAK";      break;
   case REMOVE_WEAK       : ret = "REMOVE WEAK";       break;
   case EVENTW            : ret = "EVENTW";            break;
   case REM_RDG_UNI       : ret = "REM RDG UNI";       break;
   case REM_RDG_MULTI     : ret = "REM RDG MULTI";     break;
   case REM_RDP_UNI       : ret = "REM RDP UNI";       break;	
   case REM_RDP_MULTI     : ret = "REM RDP MULTI";     break;	
   case REM_ING_UNI       : ret = "REM ING UNI";       break;
   case REM_ING_MULTI     : ret = "REM ING MULTI";     break;
   case REM_INP_UNI       : ret = "REM INP UNI";       break;
   case REM_INP_MULTI     : ret = "REM INP MULTI";     break; 
   case REM_OUT           : ret = "REM OUT";           break;
   case REM_OUTG          : ret = "REM OUTG";          break;
   case REM_INSTALL_UNI   : ret = "REM INSTALL UNI";   break;
   case REM_INSTALL_MULTI : ret = "REM INSTALL MULTI"; break;	 
   case REM_REMOVE_UNI    : ret = "REM REMOVE UNI";    break;
   case REM_REMOVE_MULTI  : ret = "REM REMOVE MULTI";  break;
   case REM_EVENTW        : ret = "REM EVENTW";        break;
   case REM_RDW           : ret = "REM RDW";           break;
   case REM_INW           : ret = "REM INW";           break;
   case FRAGMENT          : ret = "FRAGMENT";          break;
   case RECONCILE         : ret = "RECONCILE";         break;
  }	
  return ret;
 }

 /**
  * Translates the codes for (header) subtype (<code>RemoteOp</code>) into Strings.
  * 
  * @param subtype (header) subtype in <code>RemoteOp</code>
  * @return textual representation
  */
 public static String translateSubtype(byte subtype)
 {
  String ret = "?";	
  switch (subtype)	
  {
   case OPEN         : ret = "OPEN";         break;
   case PASSIVE_OPEN : ret = "PASSIVE OPEN"; break;
   case REPLY        : ret = "REPLY";        break;
   case REJECT       : ret = "REJECT";       break;
   case ACK          : ret = "ACK";          break;
   case FIN          : ret = "FIN";          break;
  }
  return ret;
 }
 
 /**
  * Translates the codes for Policies into Strings.
  * 
  * @param policy for a LimeTupleSpace
  * @return textual representation
  */
 public static String translatePolicy(byte policy)
 {
  String ret = "?";	
  switch (policy)	
  {
   case LOSS         : ret = "LOSS";         break;
   case DUPLICATE    : ret = "DUPLICATION";  break;
   case CONSERVATIVE : ret = "CONSERVATIVE"; break;
  }
  return ret;	
 }
 
 /**
  * Translates the codes for Failures into Strings.
  * 
  * @param failure communication failure
  * @return textual representation
  */
 public static String translateFailure(byte failure)
 {
  String ret = "?";	
  switch (failure)	
  {
   case CRITICAL   : ret = "CRITICAL";   break;
   case TOTAL      : ret = "TOTAL";      break;
   case PARTIAL    : ret = "PARTIAL";    break;
   case IRRELEVANT : ret = "IRRELEVANT"; break;
  }
  return ret;	
 }
 
}
